package handler

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type BuildSuccess struct {
	Message      string `json:"username" binding:"required"`
	RepoName     string `json:"password" binding:"required"`
	RepoTag      string `json:"repoTag" binding:"required"`
	Downloaded   bool   `json:"download"`
	DownloadPath string `json:"download_path"`
}

type BuildFailure struct {
	RepoName string `json:"password" binding:"required"`
	RepoTag  string `json:"repoTag" binding:"required"`
	Url      string `json:"url" binding:"required"`
}

func SendSuccessNotification() gin.HandlerFunc {
	return func(c *gin.Context) {
		var requestBody BuildSuccess
		if err := c.ShouldBindJSON(&requestBody); err == nil {
			// 成功解析 JSON
			c.JSON(http.StatusOK, gin.H{})
		} else {
			// 如果有错误，返回一个 400 Bad Request 的响应，并附带错误信息
			c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		}
	}
}

func SendFailNotification() gin.HandlerFunc {
	return func(c *gin.Context) {
		var requestBody BuildFailure
		if err := c.ShouldBindJSON(&requestBody); err == nil {
			// 成功解析 JSON
			c.JSON(http.StatusOK, gin.H{})
		} else {
			// 如果有错误，返回一个 400 Bad Request 的响应，并附带错误信息
			c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		}
	}
}
